package hu.szte.ovrt.mzst.operations;

import java.io.File;

import hu.szte.ovrt.mzst.exceptions.BadOperandException;
import hu.szte.ovrt.visitors.ExpressionVisitor;

public class CreateDirectory extends OneOperandOperation {

	public CreateDirectory(String firstOperand) {
		super(firstOperand);
	}

	@Override
	public void execute() throws BadOperandException {

		File theDir = new File(firstOperand);

		// if the directory does not exist, create it
		if (!theDir.exists()) {
			boolean result = theDir.mkdirs();
			if (result) {
				System.out.println("DIR created");
			}
		} else  {
			throw new BadOperandException("A mappa mar letezik");
		}

	}

	@Override
	public void accept(ExpressionVisitor visitor) {
		visitor.visit(this);
	}

	public String toString(){
		return "letrehozkonyvtarat " + firstOperand;
	}
}
